<?php
class VOTrip
{
	public $trip_id=-1;
	public $name;
	public $state;
	//public $description;
	//public $date;
	public $user_id;//user_id
	public $places_list;// (array of Places)
	
	
	protected $db;
	
    public function __construct($db)
    {
        $this->db = $db;
    }
	
	
	public function insert()	
    {
    	$data = array("name"=>$this->name,
                      "state"=> $this->state,
                      "user_id"=>$this->user_id);
    	
        $result = $this->db->insert("trip",$data);
        
        return($result);
    }
	public function fecthAll($user_id)	
    {
    	
    	$sql_trips = "SELECT * FROM trip as t where t.user_id=".$user_id;       
        $list_trips = $this->db->fetch_array_object($sql_trips,"Trip");
                
    	foreach($list_trips as $current_trip)
		{
			 $new_trip_id=$current_trip->trip_id;
			  	/***********get places list for a trip by "trip_id""**************/
      		  $sql = "SELECT p.name,p.lat,p.lon FROM trip_place as tp INNER JOIN place p ON p.id = tp.place_id where tp.trip_id=21";
        	  $place_list = $this->db->fetch_array_object($sql,"Place");	
			  $current_trip-> places_list = $place_list;     
		}
    	        	
        return($list_trips);
    }
	public function fecthPlaces($trip_id)	
    {
    	$result='test';
        return($result);
    }
    public function delete($trip_id)	
    {
    	//primero borrarlo de TRIP-PLACE
    	//then erase in TRIP
    	
    }
	public function update($trip_id)	
    {
    	//primero borrarlo de TRIP-PLACE
    	
    }
    
    
}
